﻿using NLog;
using System;
using System.Collections.Generic;
using System.Text;

namespace Stee.CAP8.ACL
{
    /// <summary>
    /// The class for write logs
    /// </summary>
    internal class LogHelper
    {
        private static Logger _logger = LogManager.GetCurrentClassLogger();

        /// <summary>
        /// write log
        /// </summary>
        /// <param name="logLevel"></param>
        /// <param name="message"></param>
        /// <param name="exception"></param>
        public static void WriteLog(LogLevel logLevel, string message, Exception exception = null)
        {
            LogEventInfo theEvent = new LogEventInfo(logLevel, _logger.Name, message);
            theEvent.Properties["LogType"] = LogType.Middleware.ToString();
            theEvent.Exception = exception;
            switch (logLevel.ToString())
            {
                case "Debug":
                    if (_logger.IsDebugEnabled)
                    {
                        _logger.Log(theEvent);
                    }
                    break;

                case "Trace":
                    if (_logger.IsTraceEnabled)
                    {
                        _logger.Log(theEvent);
                    }
                    break;

                case "Warn":
                    if (_logger.IsWarnEnabled)
                    {
                        _logger.Log(theEvent);
                    }
                    break;

                case "Info":
                    if (_logger.IsInfoEnabled)
                    {
                        _logger.Log(theEvent);
                    }
                    break;

                case "Error":
                    if (_logger.IsErrorEnabled)
                    {
                        _logger.Log(theEvent);
                    }
                    break;

                default:
                    _logger.Log(theEvent);
                    break;
            }
        }
    }

    internal enum LogType
    {
        Web,
        DataBase,
        ApiRequest,
        Middleware
    }
}
